#include "TCP_socket.hpp"
#include <cstdlib>

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        std::cout << "server ip port" << std::endl;
        exit(1);
    }
    TCP_socket server;
    string ip = argv[1];
    uint16_t port = static_cast<uint16_t>(atoi(argv[2]));
    sockaddr_in addr;
    addr.sin_addr.s_addr = inet_addr(ip.c_str());
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    socklen_t len = sizeof(addr);

    if (!server.Bind(ip, port))
    {
        perror("server bind");
        exit(1);
    }
    server.Listen();

    string buf;//接收数据
    string ip_rcv;
    uint16_t port_rcv;
    
    while(1)
    {
        server.Accept_link(ip_rcv, port_rcv);
    }

    return 0;
}
